package cn.sinata.wanglin.adapter;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.hyphenate.easeui.utils.EaseSmileUtils;
import com.xilada.xldutils.adapter.HFRecyclerAdapter;
import com.xilada.xldutils.adapter.util.ViewHolder;
import com.xilada.xldutils.utils.ActivityUtil;
import java.util.List;
import cn.sinata.wanglin.R;
import cn.sinata.wanglin.commonutils.Constant;
import cn.sinata.wanglin.model.SendToMeBean;
import cn.sinata.wanglin.utils.ExpUtils;
import cn.sinata.wanglin.utils.RelativeDateFormat;
import cn.sinata.wanglin.village.activity.ActivedetailActivity;
import cn.sinata.wanglin.village.activity.AllUserInfoActivity;
import cn.sinata.wanglin.village.activity.MakecomplaintsdetailActivity;


public class SendToMeAdapter extends HFRecyclerAdapter<SendToMeBean> {
    Context mContext;
    public SendToMeAdapter(List<SendToMeBean> mData, Context mContext)
    {
        super(mData, R.layout.item_sendtome);
        this.mContext=mContext;
    }

    @Override
    public void onBind(int position, final SendToMeBean data, ViewHolder holder) {
        if(data.getImg()!=null&&!TextUtils.isEmpty(data.getImg().getImgUrl())){
            ((SimpleDraweeView) holder.bind(R.id.iv_contentimg)).setImageURI(data.getImg().getImgUrl());
            holder.bind(R.id.iv_contentimg).setVisibility(View.VISIBLE);
        }else{
            holder.bind(R.id.iv_contentimg).setVisibility(View.GONE);
        }
        if(!TextUtils.isEmpty(data.getIsanonymity())&&"1".equals(data.getIsanonymity())){
            ((SimpleDraweeView) holder.bind(R.id.iv_headview)).setImageURI(Uri.parse("res://mipmap/" + R.mipmap.ic_isanonymity));

        }else{
            ((SimpleDraweeView) holder.bind(R.id.iv_headview)).setImageURI(data.getHeadUrl());
        }
        holder.bind(R.id.iv_headview).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if("1".equals(data.getIsanonymity())){
                    return;
                }
                ActivityUtil.create(mContext).go(AllUserInfoActivity.class).put("friendID",data.getUserId())
                        .start();

            }
        });
        if(!TextUtils.isEmpty(data.getName())){
            holder.setText(R.id.tv_username,data.getName());

        }else{
            holder.setText(R.id.tv_username,Constant.DEFULT_NICKNAME);
        }
        switch (ExpUtils.getExpValue(data.getExp())){

            case 1:
                Resources res1 = mContext.getResources();
                Drawable img_off1 = res1.getDrawable(R.mipmap.ic_exp1);
                img_off1.setBounds(0, 0, img_off1.getMinimumWidth(), img_off1.getMinimumHeight());
                ((TextView)holder.bind(R.id.tv_username)).setCompoundDrawables(null, null, img_off1, null); //设置右图标
                break;
            case 2:
                Resources res2 = mContext.getResources();
                Drawable img_off2 = res2.getDrawable(R.mipmap.ic_exp2);
                img_off2.setBounds(0, 0, img_off2.getMinimumWidth(), img_off2.getMinimumHeight());
                ((TextView)holder.bind(R.id.tv_username)).setCompoundDrawables(null, null, img_off2, null); //设置右图标
                break;
            case 3:
                Resources res3 = mContext.getResources();
                Drawable img_off3 = res3.getDrawable(R.mipmap.ic_exp3);
                img_off3.setBounds(0, 0, img_off3.getMinimumWidth(), img_off3.getMinimumHeight());
                ((TextView)holder.bind(R.id.tv_username)).setCompoundDrawables(null, null, img_off3, null); //设置右图标
                break;
            case 4:
                Resources res4 = mContext.getResources();
                Drawable img_off4 = res4.getDrawable(R.mipmap.ic_exp4);
                img_off4.setBounds(0, 0, img_off4.getMinimumWidth(), img_off4.getMinimumHeight());
                ((TextView)holder.bind(R.id.tv_username)).setCompoundDrawables(null, null, img_off4, null); //设置右图标
                break;
            case 5:
                Resources res5 = mContext.getResources();
                Drawable img_off5 = res5.getDrawable(R.mipmap.ic_exp5);
                img_off5.setBounds(0, 0, img_off5.getMinimumWidth(), img_off5.getMinimumHeight());
                ((TextView)holder.bind(R.id.tv_username)).setCompoundDrawables(null, null, img_off5, null); //设置右图标
                break;
            case 6:
                Resources res6 = mContext.getResources();
                Drawable img_off6 = res6.getDrawable(R.mipmap.ic_exp6);
                img_off6.setBounds(0, 0, img_off6.getMinimumWidth(), img_off6.getMinimumHeight());
                ((TextView)holder.bind(R.id.tv_username)).setCompoundDrawables(null, null, img_off6, null); //设置右图标
                break;
        }


        if(!TextUtils.isEmpty(data.getIndustry())){
            holder.setText(R.id.tv_industry,data.getIndustry().toString().trim());
        }else{
            holder.setText(R.id.tv_industry,"暂无");
        }

        if(!TextUtils.isEmpty(data.getBelongLabel())){
            holder.setText(R.id.tv_lable,data.getBelongLabel().toString().trim());
        }else{
            holder.setText(R.id.tv_lable,"暂无");
        }
        if(!TextUtils.isEmpty(data.getCreateDate())){
            holder.setText(R.id.tv_time, RelativeDateFormat.format(data.getCreateDate()));
        }else{
            holder.setText(R.id.tv_time,"");
        }
        if(!TextUtils.isEmpty(data.getTxt())){
            ((TextView) holder.bind(R.id.tv_content)).setText(EaseSmileUtils.getSmiledText(mContext,data.getTxt()));
        }else{
            holder.setText(R.id.tv_content,"暂无发布内容");
        }
//        commentType	number	评论类型（0：点赞；1：文字）
        if(!TextUtils.isEmpty(data.getCommentType())){
            if("0".equals(data.getCommentType())){
                holder.setText(R.id.tv_commentcontent,"给你点了赞");
            }else if ("1".equals(data.getCommentType())){
                ((TextView) holder.bind(R.id.tv_commentcontent)).setText(EaseSmileUtils.getSmiledText(mContext,data.getContent()));
            }else{
                holder.setText(R.id.tv_commentcontent,"暂无评论");
            }

        }else{
            holder.setText(R.id.tv_commentcontent,"暂无评论");
        }

        holder.bind(R.id.tv_content).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                externalType	string	评论文章类型A:八卦，B:吐槽，C:圈子，D活动,F新闻
                if("A".equals(data.getExternalType())){
                    ActivityUtil.create(mContext).go(MakecomplaintsdetailActivity.class)
                            .put("type","2")
                            .put("id",data.getExternalId())
                            .start();
                }else if("B".equals(data.getExternalType())){
                    ActivityUtil.create(mContext).go(MakecomplaintsdetailActivity.class)
                            .put("type","1")
                            .put("id",data.getExternalId())
                            .start();
                }
                else if("C".equals(data.getExternalType())){
                }
                else if("D".equals(data.getExternalType())){

                    ActivityUtil.create(mContext).go(ActivedetailActivity.class)
                            .put("id",data.getExternalId())
                            .start();
                }

            }
        });


    }

}
